import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  UseInterceptors,
  UsePipes,
  ParseIntPipe,
  UseFilters,
} from '@nestjs/common';
import { UseAopService } from './use-aop.service';
import { CreateUseAopDto } from './dto/create-use-aop.dto';
import { UpdateUseAopDto } from './dto/update-use-aop.dto';
import { UseAopGuard } from './use-aop.guard';
import { TimoutInterceptor } from '../timout/timout.interceptor';
import { ValidatePipe } from 'src/validate/validate.pipe';
import { MyExceptionFilter } from 'src/my-exception/my-exception.filter';

@Controller('use-aop')
// @UseGuards(UseAopGuard) // 使用 使用装饰器 使用守卫
export class UseAopController {
  constructor(private readonly useAopService: UseAopService) {}

  @Post()
  create(@Body() createUseAopDto: CreateUseAopDto) {
    return this.useAopService.create(createUseAopDto);
  }

  @Get()
  @UseInterceptors(TimoutInterceptor)
  // @UseGuards(UseAopGuard) // 使用守卫
  findAll() {
    return this.useAopService.findAll();
  }

  @Get(':id')
  //   @UsePipes(ValidatePipe)
  //   findOne(@Param('id') id: string) {
  //   findOne(@Param('id', ValidatePipe) id: string) {
  findOne(@Param('id', ParseIntPipe) id: string) {
    console.log('-findOne--');
    return this.useAopService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateUseAopDto: UpdateUseAopDto) {
    return this.useAopService.update(+id, updateUseAopDto);
  }

  @Delete(':id')
  @UseFilters(new MyExceptionFilter())
  remove(@Param('id', ParseIntPipe) id: string) {
    console.log('---remove---', id);
    // throw new Error('ww');
    return this.useAopService.remove(+id);
  }
}
